package com.csmk.control;

import com.alibaba.fastjson2.JSONObject;
import com.github.serezhka.airplay.player.gstreamer.ScreenConfig;
import okhttp3.Callback;


public class MKSApi {

    private MKSClient mksClient;

    public void setDeviceIp(String deviceIp) {
        mksClient = new MKSClient(deviceIp);
    }

    private JSONObject commonTouch(int x,int y,String type){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("x",x*ScreenConfig.scale);
        jsonObject.put("y",y*ScreenConfig.scale);
        jsonObject.put("index",1);
        jsonObject.put("type",type);
        return jsonObject;
    }

    public void touchDown(int x,int y){
        if (mksClient == null){
            return;
        }
        mksClient.sendTask(new Task(TaskType.TASK_PERFORM_TOUCH,commonTouch(x, y,"down")));
    }

    public void touchUp(int x,int y){
        if (mksClient == null){
            return;
        }
        mksClient.sendTask(new Task(TaskType.TASK_PERFORM_TOUCH,commonTouch(x, y,"up")));
    }

    public void move(int x,int y){
        if (mksClient == null){
            return;
        }
        mksClient.sendTask(new Task(TaskType.TASK_PERFORM_TOUCH,commonTouch(x, y,"move")));
    }

    public void inputText(String text){
        mksClient.sendTask(new Task(TaskType.TASK_INPUT,text));
    }

    public void delText(){
        mksClient.sendTask(new Task(TaskType.TASK_DEL,1));
    }

    public void home(){
        mksClient.sendTask(new Task(TaskType.TASK_HOME,null));
    }

    public void switcher(){
        mksClient.sendTask(new Task(TaskType.TASK_SWITCH,null));
    }

    public void getScreenSize(Callback callback){
        mksClient.sendTask(new Task(TaskType.TASK_SCREEN_SIZE,1),callback);
    }

}
